<?php

namespace App\Http\Livewire;

use App\Models\Team as TeamModel;
use Livewire\Component;

class TeamView extends Component
{
    public $team;
    public $view = 'main';
    public $searchString;

    protected $listeners = ['loadModelRelation'];

    public function mount($id)
    {
        $this->team = TeamModel::findOrFail($id);
    }

    public function switchView($view)
    {
        $this->view = $view;
        $this->searchString = '';

        switch ($this->view) {
            case 'main':
                break;
            case 'users':
                $this->loadModelRelation('users');
                break;
            case 'links':
                $this->loadModelRelation('links');
                break;
            case 'tasks':
                $this->loadModelRelation('tasks');
                break;
        }
    }

    public function loadModelRelation($relationName)
    {
        $this->team->load($relationName);
    }

    public function render()
    {
        return view('livewire.team.team-view');
    }
}
